package cn.action;

import cn.base.BaseAction;
import cn.domain.Forum;
import cn.domain.PageBean;
import cn.utils.HQLHelper;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * Created by Administrator on 2017/4/1 0001.
 */
@Controller
@Scope("prototype")
public class forumManageAction extends BaseAction<Forum> {
    /**
     * 跳转list
     * @return
     */
    public String list(){
//            List<Forum> list=forumService.findAll();
//            getValueStack().set("list",list);
        HQLHelper hqlHelper=new HQLHelper(Forum.class);
        hqlHelper.orDerBy(" position ",true);
        hqlHelper.getHqlList();
        PageBean pageBean=forumService.getPageBean(hqlHelper,getCurrentPage());
        List<Forum> list=pageBean.getRecordList();
        getValueStack().set("list",list);
        getValueStack().push(pageBean);
        return "list";
    }

    /**
     * 跳转添加页面
     * @return
     */
    public String addUi(){
        model.setId(0L);
        return "add";
    }

    /**
     * 保存
     * @return
     */
    public String save(){
        if(model.getId()==0){
            forumService.Save(model);
        }else{
            forumService.Update(model);
        }
        return "toList";
    }

    /**
     * 删除
     * @return
     */
    public String delete(){
         forumService.Delete(model.getId());
        return "toList";
    }

    /**
     * 跳转修改页面
     * @return
     */
    public String editUi(){
        Forum forum=forumService.getById(model.getId());
        getValueStack().push(forum);
        return "add";
    }
    /**
     * 上移功能
     */
    public String moveUp(){
        forumService.moveUp(model.getId());
        return "toList";
    }
    /**
     * 下移功能
     */
    public String moveDown(){
        forumService.moveDown(model.getId());
        return "toList";
    }
    public String moveTop(){
        forumService.moveTop(model.getId());
        return "toList";
    }
}
